#!/usr/bin/env python
#
# Copyright 2011 Google Inc. All Rights Reserved.
# Author: sdd@google.com (Salvatore Domenick Desiano)
#
# Force the Rietveld upload script to cache the user's password. This allows
# other scripts to assume Rietveld can be used without asking the user for
# authentication. This is kind of a hack, in the sense that it imports the
# Rietveld upload script as a module. While that makes it likely to break with
# future versions of Rietveld, it's the best way to minimize duplicate code and
# ensure compatibility.
#
# usage: ./glp-issue-cache-credentials path/to/upload.py [upload.py options]

import os
import sys

script_path, script_filename = os.path.split(sys.argv[1])
script_filename, script_ext = os.path.splitext(script_filename)
sys.path.append(script_path)
rietveld = __import__(script_filename)
reload(rietveld)
os.environ['LC_ALL'] = 'C'
options, args = rietveld.parser.parse_args(sys.argv[2:])
rpc_server = rietveld.GetRpcServer(options.server,
                                   options.email,
                                   options.host,
                                   True,
                                   options.account_type)
if not rpc_server.authenticated:
  rpc_server._Authenticate()
